package germmy.home.testmultithread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class LockTest {

	
	
	Outer outer=new Outer();
	
	public static void main(String[] args) {
		new LockTest().init();
	}
	
	
	void init(){
		new Thread(new Runnable() {
			public void run() {
				while(true){
					outer.output("zhangsanshigehaoren");
				}
			}
		}).start();
		
		new Thread(new Runnable() {
			public void run() {
				while(true){
					outer.output("taiwanxiangtaidu");
				}
			}
		}).start();
		
	}
	
	
}

 class Outer{
	
	Lock lock=new ReentrantLock();//应该用子类来新建，而不是直接new Lock接口。
	void output(String name){
		lock.lock();
		try {
			for(int i=0;i<name.length();i++){
				System.out.print(name.charAt(i));
			}
			System.out.println();
		} finally{
			lock.unlock();
		}
	}
	
}







